import java.lang.reflect.Array;
import java.util.Arrays;

public class arr {
    public static void main(String[] args) {
        int[] array = {12,4,3,8,19,7};
        System.out.println("排序前: " + Arrays.toString(array));
        //System.out.println(myToString(array));
        bubbleSort(array);
        System.out.println("排序后: " + Arrays.toString(array));
       //System.out.println(myToString(array));
    }




    public static void bubbleSort(int[] array){
        //i代表的是趟数
        for (int i = 0; i <= array.length-1 ; i++) {
            //已经优化了 每次比上一次少1个
            boolean flg = false;//又一次优化
            for (int j = 0; j < array.length-1-i ; j++) {
                if (array[j] > array[j+1]){
                     int tep =  array[j];
                     array[j] = array[j+1];
                     array[j+1] = tep;
                     flg = true;
               }
            }
            if (!flg) {
                //没有交换
                return;
            }
        }
    }
}



